﻿/// <reference path="jquery.js" />

//载入错误图片
var nullimg = wwwpath + 'images/error.jpg';
function lod(t) {
    t.onerror = null;
    t.src = nullimg
}

//公共方法
$(function () {
    //键盘弹出添加类名
    var settm;
    $(document).on("focus", "input,textarea", function () {
        $("html").addClass("js-focus")
        clearTimeout(settm)
    })
    $(document).on("blur", "input,textarea", function () {
        settm=setTimeout(function () {
            $("html").removeClass("js-focus");
        }, 10)
    })
    //
})


	

//设置默认语言
var lange = {}
//遍历设置语言
function setlange_obj() {
    $("div[data-l],span[data-l],i[data-l],p[data-l],em[data-l],a[data-l]").each(function () {
        var $th = $(this),
            $thdata = $th.attr("data-l");
            $th.html(lange[$thdata]);
    })
      $("div[data-e],span[data-e],i[data-e],p[data-e],em[data-e],input[data-e]").each(function () {
        var $th = $(this),
            $thdae = $th.attr("data-e");
        $th.attr("data-error", lange[$thdae]);
        
    })

    $("input[data-p],textarea[data-p]").each(function () {
        var $th = $(this),
            $thdap = $th.attr("data-p");
        $th.attr("placeholder", lange[$thdap])
    })
}

//公用ajax
function global_ajax(url, data, call1) {

	var tim111 = setInterval(function () {
        $.showLoading();
        clearInterval(tim111);
    }, 500);
    $.ajax({
        type: "post",
        dataType: "json",
        url: url + "&l=" + getCookie("language"),
        data: data,
        headers: {
            "MEMBER-ENCODE": getCookie("yingsoft_home_encode"),
            "SHOP-ENCODE": getCookie("yingsoft_home_shop_encode")   
        },
        success: function (html) {
 			clearInterval(tim111);
            $.hideLoading();
            //系统有更新重新登录
            if(getCookie("from")=="app"){
//          	if(localStorage.getItem("setver")!=null){
//		            if(html.ver!=localStorage.getItem("setver")){  	            	
//		            	$.modal({
//		                    title: lange["1139"],
//		                    text: lange["1140"],
//		                    buttons: [
//		                      {
//			                      text: lange["1016"], onClick: function () {
//			                      	localStorage.setItem("setver",html.ver)
//			                      	window.location.href="/main.html?from=app&r="+Math.random();
//			                      }
//		                      }
//		                    ]
//		               });   
//		               return false;
//		            }
//	            }
            }
            
            if(html.status!=4)
            {
            	if(html.status==1)
	            {
	            	call1(html)
	            }else{
	            	$.modal({
	                    title: lange["1124"],
	                    text: html.msg
	               });   
	            } 
            }else
            {
              Q.go('lose-html')                
            }
            
           
            
        },
        error: function () {
        	clearInterval(tim111);
            $.hideLoading();
        	
            $.modal({
	          title: "tips",
	          text: "Loading timeout",
	          buttons: [
	            { text: "Refresh", onClick: function(){
	            	window.history.go(-1);
	            	location.reload(true)  
	            } }
	          ]
	       });
        }
    });
}


//登陆前公用ajax
function bef_ajax(url, data, call1) {
	var tim111 = setInterval(function () {
        $.showLoading();
        clearInterval(tim111);
    }, 500);
    
    $.ajax({
        type: "post",
        dataType: "json",
        url: url+ "&l=" + getCookie("language"),
        data: data,
        cache: false,
        success: function (html) {
			clearInterval(tim111);
            $.hideLoading();
			//系统有更新重新登录
            if(getCookie("from")=="app"){
            	if(localStorage.getItem("setver")!=null){
		            if(html.ver!=localStorage.getItem("setver")){  	            	
		            	$.modal({
		                    title: lange["1139"],
		                    text: lange["1140"],
		                    buttons: [
		                      {
			                      text: lange["1016"], onClick: function () {
			                      	localStorage.setItem("setver",html.ver)
			                      	window.location.href="/main.html?from=app&r="+Math.random();
			                      }
		                      }
		                    ]
		               });   
		               return false;
		            }
	            }
            }
            call1(html)
             
            
        },
        error: function () {
            clearInterval(tim111);
            $.hideLoading();
        	
            $.modal({
	          title: "tips",
	          text: "Loading timeout",
	          buttons: [
	            { text: "Refresh", onClick: function(){
	            	window.history.go(-1);
	            	location.reload(true)  
	            } }
	          ]
	       });
        }
    });
}

